<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">有我在您可放心畅饮</text>
		</view>
		<button class="btn" @tap="subscribeMessage()">乘客登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			code: null
		};
	},
	methods: {
		subscribeMessage(){
			let vthis = this;
			wx.login({
			  success (res) {
			    if (res.code) {
					let param = {
						wxCode : res.code,
						phoneCode:"154"
					}
			      //发起网络请求
			      vthis.post(vthis.Consts.API.APP_LOGIN,param,(res) => {
					  let {success,message,data} = res.data;
					  if(success){
						  
							//将数据添加到本地存储
							uni.setStorageSync("phone",data.phone);
							uni.setStorageSync("avatar",data.login.avatar);
							uni.setStorageSync("nickName",data.login.nickName);
							uni.setStorageSync("satoken",data.satoken);
					  	
					  		uni.switchTab({
					  			url:"/pages/workbench/workbench"
					  		})
					  }else{
					  	uni.showToast({
					  		title:message,
					  		icon:"error"
					  	})
					  }	
				  })
			    } else {
			      uni.showToast({
			      	title:"登录出错请稍后再试",
					icon:"error"
			      })
			    }
			  }
			})
		},
		//跳转注册页面
		toRegisterPage(){
			let vthis = this;
			uni.navigateTo({
				url:"/pages/register/register"
			})
		}
	},
	onLoad: function() {
		
	}
};
</script>

<style lang="less">
@import url('login.less');
</style>
